<?php
/**
 * Created By base
 * Author: Virus
 * Date: 2020/3/12
 * Time: 17:00
 */

namespace app\common\model\mysql;


class AuthGroup extends BaseModel
{
    /**
     * 状态获取器
     * @param $value
     * @return string
     */
    public function getStatusAttr($value)
    {
        return $value ? "<i class='fa fa-check-circle'></i>" : "<i class='fa fa-close'></i>";
    }

    public function saveData($data)
    {
        if (empty($data) || !is_array($data)) {
            return false;
        }

        return $this->allowField(true)->save($data);
    }

    public function updateById($id, $data)
    {
        $id = intval($id);
        if (empty($id) || empty($data) || !is_array($data)) {
            return false;
        }

        return $this->whereIn('id', $id)->update($data);
    }

    /**
     * @param $id
     * @return bool|int
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function deleteById($id)
    {
        $id = intval($id);
        if (empty($id)) {
            return false;
        }
        $where = [
            'id' => $id,
        ];

        return $this->where($where)->delete();
    }
}